﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace AdaptiveDeNet.CSV
{
    public class CSVwriter
    {
        public void WriteResults(string fileName, List<Result> input)
        {
            DateTime current = DateTime.Now;
            String dtFormat = "yyyy-d-MM";

            TextWriter tw = new StreamWriter(fileName + " " + current.ToString(dtFormat) + ".csv");

            for (int i = 0; i < input.Count; i++)
			{
			    tw.WriteLine(input[i].CSVresult(0.0001)); 
			}

            tw.Close();
        }

        public void WriteCEC14Results(string fileName, List<double> records, List<double> timeElapsed)
        {
            DateTime current = DateTime.Now;
            String dtFormat = "yyyy-d-MM";

            TextWriter tw = new StreamWriter(fileName + " " + current.ToString(dtFormat) + ".csv");

            records.Sort();

            tw.WriteLine("records");

            for (int i = 0; i < records.Count; i++)
            {
                tw.WriteLine(records[i]);
            }

            tw.WriteLine("");
            tw.WriteLine("");
            tw.WriteLine("timeElapsed");

            for (int i = 0; i < timeElapsed.Count; i++)
            {
                tw.WriteLine(timeElapsed[i]);
            }

            tw.Close();
        }
    }
}
